<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import=" com.demo.entity.Products"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import=" java.util.List"%>
<%@ page import=" com.demo.entity.Message"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商城-商品详细信息</title>
<script type="text/javascript">     
     function check(form) {
        var regu = /^[1-9]\d*$/;
        if(form.quantity.value == ''){
            alert("数量值不能为空 ! ");
            form.quantity.focus();
            return false;
        }
        if(!regu.test(form.quantity.value)){
            alert("必须输入整数 ! ");
            form.quantity.focus();
            return false;           
        }
    }
    function checkPage() {
        var pageMsg = document.getElementById("pageMsg");
        if(pageMsg.value == ''){
            alert("留言不能为空 ! ");
            return false;
        }else if(pageMsg.value.indexOf("/") != -1){
        	alert("留言不能存在非法字符 ! ");
            return false;
        }else if(pageMsg.value.indexOf("\\") != -1){
            alert("留言不能存在非法字符 ! ");
            return false;
        }
    }
</script>
</head>
<body>
    <form action="/WebStoreSSM/controller/addProductsNumById" method="post">
        <fieldset>
            <legend style="color: #00f"><h3> 商品详细信息  . . . </h3></legend>
            <br>
            <%
            Products products = (Products)session.getAttribute("products");
            %>
            <input type="hidden" name="id" value="<%=products.getProduct_id()%>"/>
            <table>
                <tr><th>商品号：</th><th><%=products.getProduct_id()%></th></tr>
                <tr><th>商品名：</th><th><%=products.getName()%></th></tr>
                <tr><th>价格：</th><th><%=products.getPrice()%></th></tr>
                <tr><th>库存量：</th><th><%=products.getPnum()%></th></tr>
                <tr><th>类别：</th><th><%=products.getCategory()%></th></tr>
                <tr><th>详细信息：</th><th><%=products.getDescription()%></th></tr>
                <tr><th><input type="text" name="quantity" id="quantity"  value="${succMsg }-商品数量" onfocus="if(value=='${succMsg }-商品数量')value=' ' "/></th>
                        <th><input type="submit" value="加入购物车" onclick="return check(this.form)"/></th></tr>
                <tr><th colspan="2"><a href="/WebStoreSSM/views/product_list.jsp">查看商品列表</a></th></tr>
            </table>
        </fieldset>
    </form>
    <fieldset>
       <legend style="color: #00f"><h3> 留言区  . . . </h3></legend>
       <form action="/WebStoreSSM/controller/insertMessageInfo/<%=products.getProduct_id()%>" method="post" onsubmit="return checkPage();">
           <label><textarea rows="2" cols="18" name="pageMsg" id="pageMsg"></textarea></label>
           <input type="submit" align="right" value="留言" />
       </form>
       
       <br><br>
       <% 
           List<Message> messageInfo = (ArrayList<Message>) session.getAttribute("messageInfo");
           if(messageInfo != null){
            for(Message msgInfo : messageInfo){
       %>
       <table>
           <tr><th style="color: #f0f"><%=msgInfo.getUsername() %>：</th>
                   <th><font size="2px"><%=msgInfo.getContent() %></font> </th></tr>
       </table>
       <%} }%>
    </fieldset>
</body>
</html>